import { createApp } from 'vue';
import ArcoVue from '@arco-design/web-vue';
import '@arco-themes/vue-taolu-publishing-platform/css/arco.css';
import ArcoVueIcon from '@arco-design/web-vue/es/icon';
import globalComponents from '@/components';
import router from './router';
import store from './store';
import i18n from './locale';
import directive from './directive';
// 移除无条件导入Mock服务的代码
// import './mock';
import App from './App.vue';
// Styles are imported via arco-plugin. See config/plugin/arcoStyleImport.ts in the directory for details
// 样式通过 arco-plugin 插件导入。详见目录文件 config/plugin/arcoStyleImport.ts
// https://arco.design/docs/designlab/use-theme-package
import '@/assets/style/global.less';
import '@/api/interceptor';

// 检查环境变量是否正确加载
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL;
const useMock = import.meta.env.VITE_USE_MOCK;
const disableEslint = import.meta.env.VITE_ESLINT_DISABLE;

console.log('应用启动时的环境变量:');
console.log('VITE_API_BASE_URL:', apiBaseUrl || '未设置');
console.log('VITE_USE_MOCK:', useMock || '未设置');
console.log('VITE_ESLINT_DISABLE:', disableEslint || '未设置');

// 如果环境变量未正确加载，手动设置默认值
if (!apiBaseUrl) {
  console.warn('VITE_API_BASE_URL未设置，使用默认值: http://localhost:8080');
  // 在window对象上设置，以便其他地方可以访问
  window.VITE_API_BASE_URL = 'http://localhost:8080';
}

// 只有在明确设置为true时才加载Mock
if (useMock === 'true') {
  console.log('启用Mock服务');
  import('./mock');
} else {
  console.log('禁用Mock服务');
  // 在window对象上设置，以便其他地方可以访问
  window.VITE_USE_MOCK = 'false';
}

const app = createApp(App);

app.use(ArcoVue, {});
app.use(ArcoVueIcon);

app.use(router);
app.use(store);
app.use(i18n);
app.use(globalComponents);
app.use(directive);

app.mount('#app');
